
float4 ctc;
float radius;
float intensity;
float age;
float waves_per_second;
float4x4 View;
float4x4 Projection;
texture Texture;
sampler Sampler = sampler_state
{
    Texture = (Texture);
    
    MinFilter = Linear;
    MagFilter = Linear;
    MipFilter = Linear;
    
    AddressU = Clamp;
    AddressV = Clamp;
};

struct VertexShaderInput
{
    float4 Position : POSITION0;
};

struct VertexShaderOutput
{
    float4 Position : POSITION0;
    float2 Texcoord : TEXCOORD0;
};

VertexShaderOutput VS(VertexShaderInput input)
{
    VertexShaderOutput output;
    output.Position = input.Position.xzyw;
    output.Position.xy = (output.Position.xy*2.0 - 1.0);
    output.Position.w = 1.0;
    output.Texcoord = input.Position.xz;
    output.Texcoord.y = 1.0 - output.Texcoord.y;
    return output;
}

float4 PS(VertexShaderOutput input) : COLOR0
{
    //return float4(input.Texcoord.x, input.Texcoord.y, 0, 1);
    #define MyPI 3.1415926535897932384626433832795
    #define MaxDist 0.70710678118654752440084436210485
    
    float wave_num = 24.0;
    float wave_length = MaxDist/wave_num;
    float sample_max_offset = (wave_length/4)*cos(MyPI*0.5*age)*intensity;
    
    float2 diff = input.Texcoord - ctc;
    float dist = length(diff);
    float2 ndiff = normalize(diff);
    
    float distortion = sin(2*MyPI*(-waves_per_second*age + dist / wave_length));
    
    float2 new_tc = input.Texcoord + ndiff*distortion*sample_max_offset*(1.0 - smoothstep(radius, radius+0.05,dist));
    float4 c = tex2D(Sampler,new_tc);
    return c;
}

technique Technique1
{
    pass Pass1
    {
        VertexShader = compile vs_2_0 VS();
        PixelShader = compile ps_2_0 PS();
    }
}
